package com.internetCafes.spms.web.project.controller;


import com.internetCafes.spms.common.base.BaseWebController;
import com.internetCafes.spms.common.module.excel.ExcelUtils;
import com.internetCafes.spms.common.module.excel.po.ProjectExcel;
import com.internetCafes.spms.common.utils.entity.RR;
import com.internetCafes.spms.common.utils.entity.page.PageItemDTO;
import com.internetCafes.spms.common.utils.entity.page.PageItemVO;
import com.internetCafes.spms.web.project.entity.dto.projectconfig.ProjectCertificatePagingDTO;
import com.internetCafes.spms.web.project.entity.dto.projectconfig.ProjectPagingDTO;
import com.internetCafes.spms.web.project.entity.dto.projectconfig.ProjectSaveDTO;
import com.internetCafes.spms.web.project.entity.dto.projectconfig.ProjectUpdateDTO;
import com.internetCafes.spms.web.project.entity.vo.projectconfig.ProjectCertificatesPagingVO;
import com.internetCafes.spms.web.project.entity.vo.projectconfig.ProjectInfoVO;
import com.internetCafes.spms.web.project.entity.vo.projectconfig.ProjectPagingVO;
import com.internetCafes.spms.web.project.service.IProjectConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * <p>
 * 项目信息管理表 前端控制器
 * </p>
 *
 * @author Zj
 * @since 2021-04-27
 */
@Api(tags = {">>>项目列表"})
@RestController
@RequestMapping("/project/projectConfig")
public class ProjectConfigController extends BaseWebController {

    @Autowired
    private IProjectConfigService projectConfigService;

    @ApiOperation(value = "项目信息导出")
    @PostMapping("/export")
    @RequiresPermissions("project:projectConfig:list")
    public void export(@RequestBody PageItemDTO dto, HttpServletResponse response) {

        List<ProjectExcel> projectExcels = projectConfigService.exportProjectInfos();
        ExcelUtils.exportExcel(projectExcels, "项目统计", "项目统计", ProjectExcel.class, "项目统计.xls", response);
    }

    /**
     * 项目证书列表
     */
    @ApiOperation(value = "项目证书列表")
    @PostMapping("/certificates/paging")
    @RequiresPermissions("project:projectConfig:info")
    public RR<PageItemVO<ProjectCertificatesPagingVO>> certificatesPaging(@RequestBody PageItemDTO<ProjectCertificatePagingDTO> dto) {
        PageItemVO<ProjectCertificatesPagingVO> result = projectConfigService.certificatesPaging(dto);
        return new RR().successData(result);
    }

    /**
     * 项目详情
     */
    @ApiOperation(value = "项目详情")
    @GetMapping("/info/{id}")
    @ApiParam(required = true, name = "唯一标识id", value = "id")
    @RequiresPermissions("project:projectConfig:info")
    public RR<ProjectInfoVO> info(@PathVariable("id") Long id) {
        ProjectInfoVO result = projectConfigService.info(id);
        return new RR().successData(result);
    }

    /**
     * 项目删除
     */
    @ApiOperation(value = "项目删除")
    @GetMapping("/delete/{id}")
    @ApiParam(required = true, name = "唯一标识id", value = "id")
    @RequiresPermissions("project:projectConfig:delete")
    public RR delete(@PathVariable("id") Long id) {
        projectConfigService.deleteById(id);
        return RR.success("删除成功");
    }

    /**
     * 项目修改
     */
    @ApiOperation(value = "项目修改")
    @PostMapping("/update")
    @RequiresPermissions("project:projectConfig:update")
    public RR update(@RequestBody ProjectUpdateDTO dto) {
        projectConfigService.update(dto);
        return RR.success("修改成功");
    }

    /**
     * 项目列表
     */
    @ApiOperation(value = "项目列表")
    @PostMapping("/paging")
    @RequiresPermissions("project:projectConfig:list")
    public RR<PageItemVO<ProjectPagingVO>> paging(@RequestBody PageItemDTO<ProjectPagingDTO> dto) {
        PageItemVO<ProjectPagingVO> result = projectConfigService.page(dto);
        return new RR().successData(result);
    }

    /**
     * 新增项目
     */
    @ApiOperation(value = "新增项目")
    @PostMapping("/save")
    @RequiresPermissions("project:projectConfig:save")
    public RR save(@RequestBody ProjectSaveDTO dto) {
        projectConfigService.save(dto);
        return RR.success("新增成功");
    }
}
